//////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // -------------------- Ebrahim Foulaadvand & Somayyeh Belbasi, 30 July 2009 --------------------------- // // // // The programme "ForcedCoupledOscillators" evaluates the temporal evolution of a system of forced // // coupled harmonic oscillator which are connected to each other by springs. It also gives you the // // amplitude frequency dependence of oscillators. The fix boundary condition is used. The second order // // Runge-Kutta and Euler-Cromer algorithms are implemented for solving the motion equations. // // // // // //////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include #include using namespace std; main() { randomize(); const N=3, T=30000; // N= number of oscillators, T= number of simulation timesteps. double delt=0.01,F0=0.5,w=1,delw=0.05,E; // delt=timestep, F0=driving force amplitude. //w=Sinusoidal driving force frequency, delw=increment for w. int i,j,s,S=10,t; vector< double > m(N+2,0),k(N+3,0),D(N+2,0),xEC(N+2,0),vEC(N+2,0),x(N+2,0),v(N+2,0),k1x(N+2,0),k2x(N+2,0), k1v(N+2,0),k2v(N+2,0); // Arrays "m" and "k" store the oscillators masses and the spring constants. Arrays "x" and "v" store // oscillators positions and velocities computed by RK2 algorithm. Arrays "xEC" and "vEC" store // oscillators positions and velocities computed by EC (Euler-Cromer) algorithm. We use fixed boundary // condition i.e.; end masses are only connected to one adjacent mass. The first mass is connected to // the driving force. ofstream file1 ("xEC 2.plt"); //output file for the poistion time series of particle 2 (EC algorithm). ofstream file2 ("xRK 2.plt"); //output file for the poistion time series of particle 2 (RK2 algorithm). ofstream file3 ("D1(w).plt"); //output file for the frequency dependence of particle 1. ofstream file4 ("D2(w).plt"); //output file for the frequency dependence of particle 2. ofstream file5 ("D3(w).plt"); //output file for the frequency dependence of particle 3. for (int i=1;i<=N;i++){ m[i]=1; k[i]=1; } k[N+1]=1; //----------- Euler-Cromer algorithm -------------------- for (int s=1;s<=S;s++){ w=s*delw; cout<<"s= "<D[i]) ) D[i]=fabs(xEC[i]); } file1<